<?php
class Model_agenda extends TW_Model {
    
    private $_table = 'agenda';
    
    public function getAll() {
        return $this->db->select("SELECT * FROM {$this->_table}");
    }
    
    public function getById($id) {
        
        $id = (int) $id;
        
        return $this->db->select("SELECT * FROM {$this->_table} WHERE id = :id", array(':id' => $id), false);
        
    }
    
    public function getLike($busca) {
        return $this->db->select("SELECT * FROM {$this->_table} WHERE nome LIKE :busca", array(':busca' => $busca));
    }
    
    public function delete($id) {
        $id = (int) $id;
        return $this->db->delete($this->_table, "id = '$id'");
    }
    
    public function insert($entry = array()) {
        return $this->db->insert($this->_table, $entry);
    }
    
    public function update($entry, $id) {
        $where = "id = " . (int) $id;
        return $this->db->update($this->_table, $entry, $where);
    }
    
}